home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / pdisk.zip / PART.H < prev    next >
Text File  |  1989-01-12  |  6KB  |  153 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stddef.h>
  4. #include <string.h>
  5.  
  6. typedef unsigned char byte;
  7. typedef unsigned int word;
  8. typedef unsigned long dword;
  9.  
  10. #pragma pack(1)    /* for OS structures, pack on byte boundaries (i.e. not at all)
  11.                  */
  12.  
  13. typedef struct part_rec {        /* one partition's data */
  14.     byte boot_ind,    /* 0x80 if this is the bootable one, else 0 */
  15.          s_head;    /* starting head */
  16.     word s_sec_cyl; /* somewhat screwy combo of sector and cylinder */
  17.     byte sys_ind,    /* which OS */
  18.          e_head;    /* ending locations */
  19.     word e_sec_cyl;
  20.     dword rel_sect,    /* number of sectors BEFORE this partition */
  21.          num_sects;    /* number of sectors in this partition */
  22. } PARTITION;
  23.  
  24. /* a partition pictorially: 0  begin    |boot ind |head |  S  | CYL |
  25.  *                          4  end      |syst ind |head |  S  | CYL |
  26.  *                          8  rel sect | low word      | high word |
  27.  *                          C  num sect | low word      | high word |
  28.  * to quote from the PC-DOS Technical Reference Manual (p. G-2) on the setup
  29.  * of the two byte long combined sector and cylinder number:
  30.  *       The 1-byte fields labelled "CYL" contain the low-order 8 bits of
  31.  *       the cylinder number -- the high order 2 bits are in the high order
  32.  *       2 bits of the "S" (sector) field.  This corresponds with the ROM
  33.  *       BIOS Interrupt hex 13 (disk I/O) requirement, to allow for a 10 bit
  34.  *       cylinder number.
  35.  * Programmer's note:  whoever wrote the BIOS this way is a sick puppy.
  36.  */
  37.  
  38. /* These macros descramble the above structure.  Note that get/put_cyl is only
  39.  * guaranteed to work if the argument is a word (i.e. unsigned int).
  40.  */
  41.  
  42. #define put_sec_cyl(sec,cyl)  ((sec & 0x3f) | (cyl << 8) | ((cyl & 0x300) >> 2))
  43. #define get_sec(x)  (x & 0x3f)
  44. #define get_cyl(x)  ((x >> 8) | ((x<<2) & 0x300))
  45.  
  46. typedef struct {
  47.     word bytes_per_sec;        /* number of bytes per sector */
  48.     byte secs_per_au;        /* sectors per allocation unit */
  49.     word res_sectors;         /* reserved sectors */
  50.     byte nfats;            /* number of FATS */
  51.     word nroot_ents,         /* max number of root directory entries */
  52.          nsectors;             /* sectors in logical image */
  53.     byte media_des;         /* media descriptor */
  54.     word secs_in_fat;        /* number of FAT sectors */
  55. } BPB;
  56.     
  57. typedef struct {
  58.     char boot_jump[3],
  59.          oem_name[8];
  60.     BPB bpb;
  61.     word secs_per_track,    /* sector per track */
  62.          nheads,            /* number of heads */
  63.          nhidden;            /* number of hidden sectors */
  64.     char boot_code[0x1a0];            /* magic */
  65.     PARTITION ptable[4];
  66.     word signature;            /* should = 0xaa55 */
  67. } BOOT;
  68.  
  69. typedef struct {        /* BIOS-maintained fixed disk parameter table entry.
  70.                  * INT 0x41 (or 46 for drive 2) points to a descriptor
  71.                  * table for the current fixed drive.  See BIOS listing
  72.                  */
  73.     word fd_ncyls;            /* number of cylinders on drive */
  74.     char fd_heads;            /* number of heads on drive */
  75.     word  fd_current;    /* starting cyl for reduced write current (XT only) */
  76.     word fd_write_precomp;    /* starting cylinder for write pre-compensation
  77.                              * or -1 if no write precompensation needed.
  78.                              */
  79.     byte fd_ecc_burst,    /* max ecc data burst length (XT only) */
  80.          fd_control,    /* see below */
  81.          fd_std_time,    /* standard time out value (XT only) */
  82.          fd_format_time,    /* time out for format drive (XT only) */
  83.          fd_check_time;    /* time out for check drive (XT only) */
  84.     word fd_lz;                /* landing zone */
  85.     char fd_sec_per_track;    /* # of sectors per track */
  86.     char fd_reserved;    /* reserved for future use */
  87. } DISK_TABLE;
  88.  
  89. #pragma pack(2) /* revert back to "normal" int boundary packing */
  90.  
  91. /* defines for control byte in above fixed disk table structure:
  92.  * note that for AT, 0x80 does the same as 0x40 and only bits 2, 6 and 7
  93.  * are valid.
  94.  */
  95. #define FD_DISABLE_RETRIES 0x80        /* bit 7: disable disk access retries */
  96. #define FD_DISABLE_RETRIES2 0x40    /* bit 6: disable ecc retries (XT only) */
  97. #define FD_MORE_THAN_8_HEADS 0x04
  98.  
  99. typedef struct {                                /* decoded partition stuff */
  100.     byte sys_ind;
  101.     word s_cylinder, e_cylinder;
  102. } PARTDATA;
  103.  
  104. void pr_head(void),    
  105.      pr_part(int, PARTITION *),
  106.      boot_transfer(word, word),
  107.      erase_eol(word),
  108.      erase_eos(word),
  109.      sleep(long),
  110.      message(char *);    /* print message and wait a sec */
  111.  
  112. int get_scr_char(int, char *, char, char);
  113.  
  114. /* The following are hard-wired by DOS.
  115.  * They are included mostly for ease of reading.
  116.  *
  117.  * IMPORTANT:  "SIGNATURE" must NOT be 1 or 4.  These are * recognized by PC-DOS as valid DOS partitions and will, therefore,
  118.  * screw up a normal boot.
  119.  */
  120. #define XENIX_PART 3    /* tells device driver that this is a XENIX partition */
  121. #define DOS_PART 4        /* tells device driver that this is a DOS partition */
  122. #define XDOS_PART 5        /* an "extended DOS" partition */
  123. #define EDOS_PART 6        /* our "special DOS" partition */
  124.  
  125. #define DISK0 0x80        /* first drive on PC controller */
  126. #define DISK1 0x81        /* second drive */
  127.  
  128. #define READ 2
  129. #define WRITE 3
  130. extern  int get_scr_val(int start,char *m_str,int def_val,int low_lim,int high_lim);
  131. extern  int get_scr_char(int start,char *m_str,char low_lim,char high_lim);
  132. extern  void message(char *str);
  133. extern  void pr_head(void );
  134. extern  void pr_part(int part_no,struct part_rec *part);
  135. extern  void erase_eos(unsigned int from);
  136. extern  void erase_eol(unsigned int from);
  137. extern    void scr_scroll(unsigned, unsigned, unsigned, unsigned, unsigned, unsigned); 
  138. extern    void scr_pos(unsigned row, unsigned col),
  139.              scr_sapage(unsigned),
  140.              scr_smode(unsigned);
  141. extern    int     scr_rpos(void),
  142.              scr_gapage(void),
  143.              scr_gmode(void);
  144. extern  void init(void);
  145. extern  void clean_quit(void );
  146. extern  int make_fat(int partno,int fat_size,unsigned int secs_in_rdir);
  147. extern  int make_rdir(int partno);
  148. extern  int main(int argc, char **argv);
  149. extern  void add_part(void );
  150. extern  void del_part(void );
  151. extern  void mod_part(void );
  152. extern    void change_parms(void);
  153.